package ArrayList.demo03;

import java.util.ArrayList;

public class ReturnList {
    public static void main(String[] args) {
        ArrayList<Phone> list = new ArrayList<Phone>();
        Phone p1 = new Phone("小米",1000);
        Phone p2 = new Phone("华为",8000);
        Phone p3 = new Phone("锤子",2999);
        list.add(p1);
        list.add(p2);
        list.add(p3);
        ArrayList<Phone> phoneInfoList = getPhoneInfo(list);
        //遍历集合
        for (int i = 0; i < phoneInfoList.size(); i++) {
            Phone phone = phoneInfoList.get(i);
            System.out.println(phone.getBrand() + "," + phone.getPrice());
        }
    }
    //如果我们要返回多个数据，可以把这些数据先放到一个容器中返回
    //容器：集合，数组
    public static ArrayList<Phone> getPhoneInfo(ArrayList<Phone> list) {
        ArrayList<Phone> resultList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Phone p = list.get(i);
            int price = p.getPrice();
            if(price < 3000){
                resultList.add(p);
            }
        }
        return resultList;
    }

}
